import { getProvinceWeatherApi } from '@/apis/weather'
import weatherIcon from '@/composables/weatherIcon'
import { ref, onMounted, computed } from 'vue'

export const useProvinceWeather = () => {
  // 省份、地图、天气数据
  const weatherData = ref([])
  const getProvinceMapWeatherData = async () => {
    const res = await getProvinceWeatherApi()
    weatherData.value = res.data.data
  }
  onMounted(() => {
    getProvinceMapWeatherData()
  })
  
  // 省份、地图、天气数据从新拼接图标字段
  const weatherList = computed(() => {
    return weatherData.value.map(item => ({
      ...item,
      ...weatherIcon[item.weatherCode]
    }))
  })
  return {
    weatherList
  }
}
